//获取指定名称的cookie的值
function getcookie(objname) {
	var arrstr = document.cookie.split("; ");
	for (var i = 0; i < arrstr.length; i++) {
		var temp = arrstr[i].split("=");
		if (temp[0] == objname)
			return unescape(temp[1]);
	}
	return null;
}

//身份证填充出生日期
$(document).on('blur','.idCard',function(){
    if ($(this).parents("div").find(".certype-select").val() == '1' || $(this).parents("div").find(".certype-select").val() == 'I' ) {
        var cal = $(this).parents("div").find(".form-date");
        if ($(this).val() != "") {
            cal.val(getBirthdatByIdNo($(this).val()));
        } else {
            cal.val("");
        };
    };
});
//验证身份证号并获取出生日期
function getBirthdatByIdNo(iIdNo) {
    var tmpStr = "";
    var strReturn = "";
    if ((iIdNo.length != 15) && (iIdNo.length != 18)) {
        App.showToast("输入的身份证号位数错误");
    }
    if (iIdNo.length == 15) {
        tmpStr = iIdNo.substring(6, 12);
        tmpStr = "19" + tmpStr;
        tmpStr = tmpStr.substring(0, 4) + "-" + tmpStr.substring(4, 6) + "-" + tmpStr.substring(6);
        return tmpStr;
    } else {
        tmpStr = iIdNo.substring(6, 14);
        tmpStr = tmpStr.substring(0, 4) + "-" + tmpStr.substring(4, 6) + "-" + tmpStr.substring(6);
        return tmpStr;
    };
}
//分享弹出
function webchatShareShow(){
    var shareBox = '<div class="sharebox"></div>';
    $("body").append(shareBox);
    shadowShow();
    $(".sharebox").on("click",function(){
        $(this).remove();
        $(".ui-mask").remove();
    });
}
//遮罩层弹出
function shadowShow(){
    var uiShadow = '<div class="ui-mask"></div>';
    $("body").append(uiShadow);
    $(".ui-mask").show();
}
(function( app, document ){

    /* -----------------------------------------------
     * Toast class
     * -----------------------------------------------
     */
    function Toast( options ) {  

        var el = document.createElement('div');
        el.className = 'za-ui-toast';

        this.el = document.body.appendChild( el )
    };
    
    var pt = Toast.prototype;
    pt.show = function( msg, interval){
        
        var self = this;
        
        // 避免上一次弹出的Tast的timer隐藏后续弹出的
        if( this.timer ){ clearTimeout( this.timer ); }
        this.timer = setTimeout(function(){
            self.hide();
            self.timer = 0;
        }, (interval || 2) * 1000);

        self.el.innerHTML = msg;
        self.el.style.display = 'block';
    };
    pt.hide = function(){
        
        this.el.style.display = 'none';
    };

    // 将Toast组件注册到全局对象App上;
    app.showToast = function( msg, interval ){

        if( !app._toast_ ){
            app._toast_ = new Toast( );
        }

        app._toast_.show( msg, interval );
    };
    
    app.hideToast = function(){
        
        app._toast_.hide();
    };
    /* -----------------------------------------------
     * mask class
     * -----------------------------------------------
     */
    function Mask( options ) {  

        var el = document.createElement('div');
        el.className = 'za-ui-mask';

        this.el = document.body.appendChild( el )
    };
    var pt = Mask.prototype;

    pt.show = function( msg ){
        this.el.style.display = 'block';
    };
    
    pt.hide = function(){
        this.el.style.display = 'none';
    }

    // 将Mask组件注册到全局对象App上;
    app.showMask = function( msg, interval ){
        if( !app._Mask_ ){
            app._Mask_ = new Mask( );
        }
        app._Mask_.show( msg, interval );
    };
    
    app.hideMask = function(){
        app._Mask_ && app._Mask_.hide();
    };
    /* -----------------------------------------------
     * Loaing class
     * -----------------------------------------------
     */
    function Loading( options ) {  

        var el = document.createElement('div');
        el.className = 'za-ui-loading';

        this.el = document.body.appendChild( el )
    };
    
    var pt = Loading.prototype;
    pt.show = function( msg ){
        this.el.innerHTML = '<div class="loading-img"></div><p>'+(msg || '加载中')+'</p>';
        this.el.style.display = 'block';
    };
    
    pt.hide = function(){
        this.el.style.display = 'none';
    }

    // 将loading组件注册到全局对象App上;
    app.showLoading = function( msg, interval ){
        if( !app._loading_ ){
            app._loading_ = new Loading( );
        }
        app._loading_.show( msg, interval );
        App.showMask();
    };
    
    app.hideLoading = function(){
        app._loading_ && app._loading_.hide();
        App.hideMask();
    };

})( window.App || (window.App = {}), document );